package com.lyluly.coursemgmt.servicemodule.iService.serviceImpl;

import com.lyluly.coursemgmt.servicemodule.iDao.CourseMapper;
import com.lyluly.coursemgmt.servicemodule.iService.ICourseService;
import com.lyluly.coursemgmt.servicemodule.model.Course;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CourseServiceImpl implements ICourseService {
    @Autowired
    private CourseMapper courseMapper;

    public void addCourse(Course course) {
        course.setCreatetime(new Date());
        courseMapper.insert(course);
    }

    public Course findByCourseName(String courseName) {
        Course course = courseMapper.selectByPrimaryKey(courseName);
        return course;
    }

    public List<Course> findByCourseList() {
        return courseMapper.selectByExample(null);
    }

    public void modifyCourse(Course course) {
        courseMapper.updateByPrimaryKeySelective(course);
    }

    public void removeCourse(String courseName) {
        courseMapper.deleteByPrimaryKey(courseName);
    }
}
